/** 
 * 文件名：MaxTemperatureMapper.java 
 * 版本信息： 
 * 日期：Jun 3, 2010 
 * Copyright SafeCenterTeam@renren.com	2010 
 * 版权所有 
 * 
 */
package com.xiaonei.hadoop;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;

/**
 * 项目名称：ice-test <br>
 * 类名称：MaxTemperatureMapper <br>
 * 类描述： <br>
 * 创建人：liushaohui <br>
 * 创建时间：Jun 3, 2010 4:06:36 PM <br>
 * 修改人：liushaohui <br>
 * 修改时间：Jun 3, 2010 4:06:36 PM <br>
 * 修改备注： <br>
 * 
 * @version
 */
public class MaxTemperatureMapper extends MapReduceBase implements
        Mapper<LongWritable, Text, Text, IntWritable> {

    private static final int MISSING = 9999;

    @Override
    public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output,
            Reporter reporter) throws IOException {
        String line = value.toString();
        String year = line.substring(15, 19);
        int airTemperature;
        if (line.charAt(87) == '+') {
            airTemperature = Integer.parseInt(line.substring(88, 92));
        } else {
            airTemperature = Integer.parseInt(line.substring(87, 92));
        }
        String quality = line.substring(92, 93);

        if (airTemperature != MISSING && quality.matches("[0,1,4,5,9]")) {
            output.collect(new Text(year), new IntWritable(airTemperature));
        }
    }

    @Override
    public void configure(JobConf arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void close() throws IOException {
        // TODO Auto-generated method stub

    }
}
